#pragma once

#include <gofcl_usart_ctl0.h>

// CTL0寄存器PM位的取值：校验模式。
typedef enum {
	USART_PM_EVEN = 0,
	USART_PM_ODD = 1,
} usart_pm_e;

// CTL0寄存器WM位的取值：从静默模式唤醒方法。
typedef enum {
	USART_WM_IDLE = 0,
	USART_WM_MASK = 1,
} usart_wm_e;

// CTL0寄存器WL位的取值：数据位数。
typedef enum {
	USART_WL_8_BIT = 0,
	USART_WL_9_BIT = 1,
} usart_wl_e;

typedef struct {
	u32_s send_sbk : 1;
	u32_s to_mute : 1;
	u32_s recv_en : 1;
	u32_s trans_en : 1;
	u32_s idle_inter_en : 1;
	u32_s unread_overrun_inter_en : 1;
	u32_s trans_complete_inter_en : 1;
	u32_s trans_avl_inter_en : 1;
	u32_s parity_err_inter_en : 1;
	usart_pm_e parity_mode : 1;
	u32_s parity_check_en : 1;
	usart_wm_e wakeup_method : 1;
	usart_wl_e word_length : 1;
	u32_s usart_en : 1;
	u32_s : 18;
} usart_ctl0_expl_s;

_Static_assert(sizeof(usart_ctl0_expl_s) == 4,
	       "Struct usart_ctl0_expl_s defined error!");

// 设置给定USART的配置0（即由CTL0寄存器配置的项）
static inline void usart_setup_0(usart_qe usart_q, usart_ctl0_expl_s ctl0) {
	union {
		usart_ctl0_expl_s e;
		usart_ctl0_s c;
	} ec = {
		.e = ctl0,
	};
	usart_wreg_ctl0_s(usart_q, ec.c);
}
